package com.zp.business.controller.patVisitIndex;

import com.zp.business.entity.patVisitIndex.bo.PatVisitIndexBo;
import com.zp.business.entity.patVisitIndex.vo.PatVisitIndexVo;
import com.zp.business.service.patVisitIndex.IPatVisitIndexService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 患者入院基本信息控制器
 * 前端访问路由地址为:/business/patVisitIndex
 *
 * @author zhang peng
 * @ date 2024-06-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/patVisitIndex")
public class PatVisitIndexController extends BaseController {

    private final IPatVisitIndexService iPatVisitIndexService;

    /**
     * 查询患者入院基本信息列表 (分页)
     */
//    @SaCheckPermission("business:patVisitIndex:list")
    @GetMapping("/selectPage")
    public TableDataInfo<PatVisitIndexVo> selectPage(PatVisitIndexBo bo, PageQuery pageQuery) {
        return iPatVisitIndexService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询患者入院基本信息列表 (不分页)
     */
//    @SaCheckPermission("business:patVisitIndex:list")
    @GetMapping("/list")
    public R<List<PatVisitIndexVo>> list(PatVisitIndexBo bo) {
        List<PatVisitIndexVo> list = iPatVisitIndexService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出患者入院基本信息列表
     */
//    @SaCheckPermission("business:patVisitIndex:export")
    @Log(title = "患者入院基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PatVisitIndexBo bo, HttpServletResponse response) {
        List<PatVisitIndexVo> list = iPatVisitIndexService.queryList(bo);
        ExcelUtil.exportExcel(list, "患者入院基本信息", PatVisitIndexVo.class, response);
    }

    /**
     * 获取患者入院基本信息详细信息
     *
     * @param visitIndexId 主键
     */
//    @SaCheckPermission("business:patVisitIndex:list")
    @GetMapping("/{visitIndexId}")
    public R<PatVisitIndexVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String visitIndexId) {
        return R.ok(iPatVisitIndexService.queryById(visitIndexId));
    }

    /**
     * 新增患者入院基本信息
     */
//    @SaCheckPermission("business:patVisitIndex:add")
    @Log(title = "患者入院基本信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PatVisitIndexBo bo) {
        return toAjax(iPatVisitIndexService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改患者入院基本信息
     */
//    @SaCheckPermission("business:patVisitIndex:edit")
    @Log(title = "患者入院基本信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PatVisitIndexBo bo) {
        return toAjax(iPatVisitIndexService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除患者入院基本信息
     *
     * @param visitIndexIds 主键串
     */
//    @SaCheckPermission("business:patVisitIndex:remove")
    @Log(title = "患者入院基本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{visitIndexIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] visitIndexIds) {
        return toAjax(iPatVisitIndexService.deleteWithValidByIds(Arrays.asList(visitIndexIds), true) ? 1 : 0);
    }
}
